<h1>Editing Food Item: <%= @food_item.name %> </h1> 

<%= error_messages_for :food_item %>

<% form_for(@food_item) do |f| %>

  <h3>Name: <%= f.text_field :name %></h3>
  <h3>Price: <%= f.text_field :price %></h3>

  <div id="right">
    <h3>Available Ingredients</h3>
    <ul>
        <% for available_ingredient_type in @available_ingredient_types %>
        <div id="ingredient_type_<%= available_ingredient_type.id %>" class="right">
            <li>
                <%= available_ingredient_type.name %>
            </li>
        </div>
        <%= draggable_element "ingredient_type_" + available_ingredient_type.id.to_s, :revert => true %>
        <% end %>
    </ul>
  </div>

  <div id="added_ingredients">
    <h3>Ingredients</h3>
        <ul id="added_ingredients_list">
            <%= render :partial => 'ingredient' %>
        </ul>
    <%= drop_receiving_element "added_ingredients", 
            :onDrop  => "function(element) {
                new Ajax.Request('" + url_for(:action => :add_ingredient, :id => @food_item.id) + "', {parameters: {ingredient_type_id: element.id}})
            }"
    %>
  </div>

  <div id="info">
    Price: <%= number_to_currency @food_item.price %>
    Cost: <%= number_to_currency @food_item.cost %>
    Profit: <%= number_to_currency @food_item.profit %>
  </div>


  <p>
    <%= f.submit "Update" %>
  </p>
  
<% end %>

<%= link_to 'Show', @food_item %> |
<%= link_to 'Back', food_items_path %>
